package com.ruibang.glass.purchase.controller;


import com.ruibang.glass.purchase.domain.req.PurchaseReturnReq;
import com.ruibang.glass.purchase.entity.PurchaseReturns;
import com.ruibang.glass.purchase.service.PurchaseReturnsService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author mameng
 */
@Api(tags = "采购退货")
@RestController
@RequestMapping("/api/glass/purchase/returns")
public class PurchaseReturnController {


    @Autowired
    private PurchaseReturnsService purchaseReturnsService;


    @PostMapping("/list")
    @ApiOperation(value = "退货列表查询", response = ResultBody.class)
    public ResultBody queryList(@RequestBody PurchaseReturnReq purchaseReturnReq) {
        return ResultBody.success(purchaseReturnsService.getPage(purchaseReturnReq));
    }

    @PostMapping("/add")
    @ApiOperation(value = "退货新增", response = ResultBody.class)
    public ResultBody add(@RequestBody PurchaseReturns purchaseReturns) {
        purchaseReturnsService.addPurchaseReturns(purchaseReturns);
        return ResultBody.success();
    }

    @PostMapping("/updatePurchaseReturns")
    @ApiOperation(value = "退换货更新", response = ResultBody.class)
    public ResultBody updatePurchaseReturns(@RequestBody PurchaseReturns purchaseReturns) {
        purchaseReturnsService.updatePurchaseReturns(purchaseReturns);
        return ResultBody.success();
    }

    @GetMapping("/getNumber")
    @ApiOperation(value = "退换货号", response = ResultBody.class)
    public ResultBody getNumber() {
        return ResultBody.success(purchaseReturnsService.getTHNumber());
    }

    @GetMapping("/processNotice/{businessId}")
    @ApiOperation(value = "流程处理通知", response = ResultBody.class)
    public ResultBody processNotice(@PathVariable("businessId") String businessId) {
        purchaseReturnsService.processNotice(businessId);
        return ResultBody.success();
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "详情", response = ResultBody.class)
    public ResultBody getPurchaseReturnsById(@PathVariable("id") String id) {
        return ResultBody.success(purchaseReturnsService.getPurchaseReturnsById(id));
    }


    @PostMapping("/updateOrderQuality")
    @ApiOperation(value = "退货新增", response = ResultBody.class)
    public ResultBody updateOrderQuality(@RequestBody List<String> returnIdList) {
        purchaseReturnsService.updateOrderQuality(returnIdList);
        return ResultBody.success();
    }

}
